function SubReqs(leftStep,budgetTop,source){
	this.leftStep = leftStep;
	this.budgetTop = budgetTop;
	this.timer = {};
	this.body = $("body");
	//this.insertQrLayer();
	this.bindEvent(this.qrLayer);
	this.source = source;
}
SubReqs.prototype.insertQrLayer = function(){
	var layerFrame = '<div id="J_qr_code_layer" style="display:none;width:100%;height:100%;background:url(/yimages/index/opacity_layer.png);position:fixed;top:0px;left:0px;z-index:80;">'+
						'<div style="width:712px;height:386px;position:fixed;top:50%;left:50%;z-index:90;margin-top:-193px;margin-left:-356px;background:white;border-radius:5px;text-align:center;overflow:hidden;position:relative;">'+
							'<div style="font-size:30px;margin-top:35px;" id="J_title">微信扫码，完成需求提交</div>'+
							'<div style="font-size:18px;margin-top:18px;color:#7F7F7F;" id="J_desc">微信扫描下方二维码后，会小二会把会议方案发到您微信</div>'+
							'<div id="J_qr_code" style="width:190px;height:190px;border:1px solid #EDEDED;margin:10px auto 0;">'+
								
							'</div>'+
							'<div style="font-size:14px;color:#7F7F7F;margin-top:10px;">如果您获取二维码失败，请点击&nbsp;<a style="color:#0078c6;text-decoration:underline" href="javascript:void(0)" id="J_regain">重新获取</a>&nbsp;<a href="javascript:void(0)" style="display:none;color:red" id="J_code_error"></a></div>'+
							'<div style="font-size:14px;color:#7F7F7F;margin-top:25px;">注：请在30分钟内完成扫码，扫码后，您可通过微信跟会小二直接沟通</div>'+
							'<div class="hander" style="position:absolute;top:10px;right:10px;" id="J_close_qr">'+
								'<img src="/yimages/index/close-qr-code.png" title="关闭" width="14px" height="14px">'+
							'</div>'+
						'</div>'+
					'</div>';
	this.body.append(layerFrame);
}
SubReqs.prototype.bindEvent = function(){
	var _that = this;
	$(".citySelect").click(function(e){
		_that.selectCity(e);
	})
	$(".typeSelect").click(function(e){
		_that.selectMtType(e);
	})
	$(".dateSelect").click(function(e){
		_that.selectDate(e);
	})
	$(".numSelect").click(function(e){
		_that.selectPerson(e);
	})
	$(".meetingSelect").click(function(e){
		_that.selectBudget(e)
	})
	$(".back_shang").click(function(){
		_that.backPrevStep();
	})
	_that.mouseoverEffects();
	$("#activityTypes li").click(function(e){
		var $obj = $(this);
		_that.mtTypesChecked(e,$obj);
	})
	
	$("#dateSelect li").click(function(e){
		var $obj = $(this);
		_that.dateChecked(e,$obj);
	})
	
	$("#activityTime li").click(function(e){
		var $obj = $(this);
		_that.timeChecked(e,$obj);
	})
	
	$("#participateCounts li").click(function(e){
		var $obj = $(this);
		_that.personChecked(e,$obj);
	})
	
	$("#meeting_budget_list li").click(function(e){
		var $obj = $(this);
		_that.budgetChecked(e, $obj);
	})
	$(".submit").click(function(){
		_that.subBaseReq();
	})
	$(".gain").click(function(){
		_that.getFreePlan($(this));
	})
	$("#J_close_qr").live("click",function(){
		_that.closeQrLayer();
	})
	$("#J_regain").live("click",function(){
		_that.regainQrCode();
	})
}
SubReqs.prototype.regainQrCode = function(){
	var _that = this;
	var $regainObj = $("#J_regain")
	if($regainObj.hasClass("getting")){
		return;
	}
	$regainObj.addClass("getting").text("获取中...");
	$.ajax({
		url: '/req-api/ajax-refresh-qr-image',
		type: 'post',
		success: function(data) {
			if(data.code == 0){
				$("#J_qr_code").html("<img src='"+data.message+"' width='200px' height='200px'>")
			}else{
				_that.showQrError(data.message);
			}
			
			$regainObj.removeClass("getting").text("重新获取");
		},
		error:function(){
			_that.showQrError("网络不给力，请稍后再试");
			$regainObj.removeClass("getting").text("重新获取");
		}
	})	
}
SubReqs.prototype.showQrError = function(error){
	var _that = this;
	clearInterval(_that.timer);
	var second = 0;
	$("#J_code_error").show().text(error);
	_that.timer = setInterval(function(){
		second++;
		if(second == 3){
			clearInterval(_that.timer);
			$("#J_code_error").hide().text('');
			second = 0;
		}
	},1000)
}
SubReqs.prototype.backPrevStep = function(){
	$(".slider").animate({"left":"0"},300);
}
SubReqs.prototype.getFreePlan = function($obj){
	var _that = this;
	if (_hmt) _hmt.push(['_trackEvent', 'index-require-achieve', 'click']);
	$obj.attr("disabled","disabled");
	$obj.val("提交中...");
	var city_code=$(".cityText_a").attr("value");  //城市代码
	var meeting_type = $(".cityText_b").attr("value");  //所属行业
	var duration=$(".cityText_e").attr("value");     //会议时长代码
	var begin_date=$(".begin_date").val();   //开始时间
	var end_date=$(".end_date").val();       //结束时间
	var capacity=$(".cityText_c").text();    //参加人数
	var budget=$(".cityText_d").text();      //会议预算
	var mobile = $("input[name=iphone]").val();  //手机号码
	var memo = $("input[name=memo]").val();  //手机号码
	var tell = /^1[34578]\d{9}$/;
	if(!tell.test(mobile)){
		$obj.removeAttr("disabled");
		$obj.val("获取方案");
		new AlertBox('请输入正确的联系方式').show();
		return;
	}
	if(_that.source===1){
		var from = 'web';
	}else if(_that.source===2){
		var from = 'web tool';
	}else if(_that.source===5){
		var from = 'booking pkg';
	}
	
	$.ajax({
		url: '/req-api/ajax-submit-req',
		type: 'post',
		data: {
			city_code:city_code,
			meeting_type:meeting_type,
			duration:duration,
			begin_date:begin_date,
			end_date:end_date,
			capacity:capacity,
			budget:budget,
			mobile:mobile,
			memo: memo,
			source:from
		},
		success: function(data) {
			if (data.code > 0) {
			    new AlertBox("网络不给力，请稍后再试!").show();
			} else {
				new AlertBox("提交成功，您的需求已受理!").show();
			}
		}
	});
}
SubReqs.prototype.showQrLayer = function(qrUrl){
	$("#J_qr_code_layer").show();
	$("#J_qr_code").html("<img src='"+qrUrl+"' width='200px' height='200px'>")
	
}
SubReqs.prototype.closeQrLayer = function(){
	$("#J_qr_code_layer").hide();
}
SubReqs.prototype.subBaseReq = function(){
	//if (_hmt) _hmt.push(['_trackEvent', 'index-require-submit', 'click']);
	var city_code=$(".cityText_a").val();   //城市代码
	var sub_city_code=$(".cityText_a").text();
	var meeting_type=$(".cityText_b").attr("value");  //会议类型代码
	var sub_meeting_type=$(".cityText_b").text();
	var duration=$(".cityText_e").attr("value");     //会议时长代码
	var sub_duration=$(".cityText_e").text();
	var iphone = $("#iphone").val();   //手机号
	var memo = $("#memo").val();   //手机号
	var end_date=$(".end_date").val();       //结束时间
	var capacity=$(".cityText_c").text();    //参加人数
	var sub_capacity=$(".cityText_c").attr("value");
	var budget=$(".cityText_d").text();      //会议预算
	var sub_budget = $(".cityText_d").attr("value");
	var identify = $("#identify").val();   //手机号
	var identifycode = $("#identifycode").val();   //手机号
	if (meeting_type == -1 || duration == -1 || sub_capacity == -1 || sub_budget == -1 || iphone == "" || memo == "" || identify=="") {
		new AlertBox('请完整填写您的内容！').show();
		return;
	}
	var tell = /^1[34578]\d{9}$/;
	if (!tell.test(iphone)) {
	    new AlertBox('请输入正确的手机号码').show();
	    return;
	}
	//alert(identifycode);
	if (identifycode != identify) {
	    new AlertBox('验证码不正确').show();
	    return;
	}
	document.getElementById("identifycode").value = "";
	$.ajax({
	    url: '/logic/sub.ashx',
	    type: 'post',
	    data: {
	        city_code: sub_city_code,
	        meeting_type: sub_meeting_type,
	        duration: sub_duration,
	        iphone: iphone,
	        memo: memo,
	        capacity: capacity,
	        budget: budget
	    },
	    success: function (data) {
	        if (data > 0) {
	            new AlertBox("网络不给力，请稍后再试!").show();
	        } else {
	            new AlertBox("提交成功，稍后我们会与您联系!").show();
	        }
	    }
	});

}
SubReqs.prototype.dateChecked = function(e,$obj){
	var dateVal=$obj.attr("value");
	var text=$obj.text();
	$(".cityText_e").attr("value", dateVal).text(text);
	$("#iphone").focus();
}
SubReqs.prototype.budgetChecked = function(e,$obj){
    stopPropagation(e);
    var value = $obj.attr("value");
	var text=$obj.text();
	$(".cityText_d").attr("value", value).text(text);
	$("#dateSelect").show();
	$("#meeting_budget_list,#activityTime,.calender").hide();
}
SubReqs.prototype.personChecked = function(e,$obj){
	stopPropagation(e);
	var value=$obj.attr("value");
	var text=$obj.text();
	$(".cityText_c").attr("value",value).text(text);
	$("#meeting_budget_list").show();
	$("#activityTypes,#activityTime,#participateCounts,.calender").hide();
}
SubReqs.prototype.timeChecked = function(e,$obj){
	stopPropagation(e);
	var value=$obj.attr("value");
	var text = $obj.text().trim();
	if (text.indexOf("\n") > -1)
	    text = text.substring(0, text.indexOf("\n"));
	$(".cityText_b").attr("value", value).text(text);
	$("#participateCounts").show();
	$("#activityTypes,#activityTime,.calender").hide();
}
SubReqs.prototype.mtTypesChecked = function(e,$obj){
	stopPropagation(e);
	var value = $obj.attr("value");
	var text = $obj.text().trim();
	if (text.indexOf("\n") > -1)
	    text = text.substring(0, text.indexOf("\n"));
	$(".cityText_a").attr("value", value).text(text);
	$("#activityTime").show();
	$("#activityTypes,.calender").hide();
}

SubReqs.prototype.selectCity = function(e){
	stopPropagation(e);
	$(".selectTypeHide,.calender").hide();
	if($("#activityTypes").css("display")=="none"){
		$("#activityTypes").show();
	}else{
		$("#activityTypes").hide();
	}
}
SubReqs.prototype.selectMtType = function(e){
	stopPropagation(e);
	$(".selectTypeHide,.calender").hide();
	if($("#activityTime").css("display")=="none"){
		$("#activityTime").show();
	}else{
		$("#activityTime").hide();
	}
}
SubReqs.prototype.selectDate = function(e){
	stopPropagation(e);
	$(".selectTypeHide,.calender").hide();
	if($("#dateSelect").css("display")=="none"){
		$("#dateSelect").show();
	}else{
		$("#dateSelect").hide();
	}
}
SubReqs.prototype.selectPerson = function(e){
	stopPropagation(e);
	$(".selectTypeHide,.calender").hide();
	if ($("#meeting_budget_list").css("display") == "none") {
	    $("#meeting_budget_list").show();
	}else{
	    $("#meeting_budget_list").hide();
	}
}
SubReqs.prototype.selectBudget = function(e){
	stopPropagation(e);
	$(".selectTypeHide,.calender").hide();
	if ($("#participateCounts").css("display") == "none") {
	    $("#participateCounts").show();
	}else{
	    $("#participateCounts").hide();
	}
}
SubReqs.prototype.mouseoverEffects = function(e){
	$(".selectTypeHide li").live('mouseover',function(){
	    $(this).css("background-color", "#00a0ea");
		$(this).css("color","#FFF");
	})
	$('.selectTypeHide li').live('mouseout', function(){
		$(this).css("background-color","#fff");
		$(this).css("color","#7B8593");
	})
}